home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / GETC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  603 b   |  23 lines

  1. /*  getc.c, from p. 440 of Turbo C Bible  */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     FILE *infile;
  6.     char buffer[81];
  7.     int i, c;
  8.                 /*  Open the file -- assuming its at     */
  9.                 /*  the root directory of C:             */
  10.     if ((infile = fopen ("c:\\config.sys", "r")) == NULL)
  11.     {
  12.     printf("fopen failed.\n");
  13.     exit(0);
  14.     }
  15.     c = getc(infile);
  16.     for(i = 0; (i < 80) && (feof(infile) == 0) && (c != '\n'); i++)
  17.     {
  18.     buffer[i] = c;
  19.     c = getc(infile);
  20.     }
  21.     buffer[i] = '\0';        /*  to make a C-style string  */
  22.     printf("First line of c:config.sys: %s\n", buffer);
  23. }